package com.atguigu.yygh.common.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author luoyin
 * @Date 16:39 2022/9/19
 **/
@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket adminConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("管理员组")
                .apiInfo(adminApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    public ApiInfo adminApiInfo(){
        return new ApiInfoBuilder()
                .description("") //描述
                .title("后台管理接口文档")   //标题
                .version("1.0")   //版本
                .contact(new Contact("","",""))  //联系信息
                .build();
    }
    @Bean
    public Docket userConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户组")
                .apiInfo(userApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/user/.*")))
                .build();
    }

    public ApiInfo userApiInfo(){
        return new ApiInfoBuilder()
                .description("") //描述
                .title("用户管理接口文档")   //标题
                .version("1.0")   //版本
                .contact(new Contact("","",""))  //联系信息
                .build();
    }
    @Bean
    public Docket apiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("其他组")
                .apiInfo(apiApiInfo())
                .select()
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    public ApiInfo apiApiInfo(){
        return new ApiInfoBuilder()
                .description("") //描述
                .title("第三方医院接口文档")   //标题
                .version("1.0")   //版本
                .contact(new Contact("","",""))  //联系信息
                .build();
    }
}
